<?php 
include('./fun.php');include('./hd_fun.php');

//$pass=g('pass');if(!$pass){exit;}
//if(md5($cfg['pass'])!=$pass){exit;}
$conn=my_sql($cfg);
$set=get_set();
echo date('Y-m-d H:i:s').'<br>';
$sql='select * from '.$cfg['e'].'order where state in (1,2,5) and js_date=0 ';
$time=time()-3600*23.5;
$sql.=' and pay_date<='.$time.' ';
$sql.=' order by id asc limit 50';
$l=db($sql);
if($l){
echo count($l).'个订单需要结算<br>';
foreach($l as $v){
unset($shop);
if($shops[$v['shop_id']]){
$shop=$shops[$v['shop_id']];
}else{
$sql='select * from '.$cfg['e'].'shop where id="'.$v['shop_id'].'" ';
$shop=db1($sql);
$shops[$v['shop_id']]=$shop;
}

if($shop){
$re=order_jiesuan($v);//进行结算
if($re=='ok'){
zd_balance($shop);
}
}
}
}else{echo '没有可以结算的订单';}

?>